package handler.store

// platform
handler.get('/wx/store/p/index'){req, resp ->
	resp.render('/store/common/index.html', [:])
}

handler.get('/wx/store/p/get-login-user'){req, resp ->
	resp.json([loginUser: 'kerry', loginLastTime: new Date().format('yyyy-MM-dd HH:mm:ss')])
}

handler.get('/wx/store/p/tab-js'){req, resp ->
	String id = req.params.id
	String type = req.params.type

	String suf = 'js' == type ? 'js' : 'html'
	def path = config.webroot + '/store/' + id + '/index.' + suf

	if(!new File(path).exists()){
		resp.sendFile config.webroot + '/store/common/demo/all.' + suf
	}else{
		resp.sendFile path
	}
}

handler.get('/wx/store/p/single'){req, resp ->
	String pluginId = req.params.pluginId

	def f = new File(config.webroot + '/store/' + pluginId + '/index.html')
	String pluginHtml = f.exists() ? f.text : ''
	String pluginJsPath = '/store/' + pluginId + '/index.js'

	resp.render('/store/common/single.html', 
		[pluginId: pluginId, pluginHtml: pluginHtml, pluginJsPath: pluginJsPath])
}
